import pymongo as pm
import pymongo.cursor


def init_mongo():
    my_client = pm.MongoClient('mongodb://localhost:27017/')
    mydb = my_client.studentdb
    mycol = mydb['Sinfo']
    return mydb, mycol


if __name__ == '__main__':
    mydb, mycol = init_mongo()
    str1 = '鬼灭之刃 无限列车篇'
    str2 = str1[0:3]
    myquery = {'Name': {'$regex': str2+'.{1,10}'}}
    mydoc = mycol.find(myquery).limit(1)
    if mydoc.count() != 0:
        for x in mydoc:
            print(x)
            print('query successfully!')
    else:
        print('没有结果')